﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ComponentModel;

namespace CasinoApp.Models
{
    public class SettingsModel : INotifyPropertyChanged
    {
        private int _numberOfPlayers;
        private string _backendUrl;
        private bool _useBackend;

        public SettingsModel()
        {
            _backendUrl = "http://192.168.0.103:8080/casino-webservice/services/CasinoApp.CasinoAppHttpSoap11Endpoint/";
        }

        public int NumberOfPlayers
        {
            get
            {
                return _numberOfPlayers;
            }
            set
            {
                if (value != _numberOfPlayers)
                {
                    _numberOfPlayers = value;
                    OnPropertyChanged("NumberOfPlayers");
                }
            }
        }

        public string BackendUrl
        {
            get
            {
                return _backendUrl;
            }
            set
            {
                if (value != _backendUrl)
                {
                    _backendUrl = value;
                    OnPropertyChanged("BackendUrl");
                }
            }
        }

        public bool UseBackend
        {
            get
            {
                return _useBackend;
            }
            set
            {
                if (value != _useBackend)
                {
                    _useBackend = value;
                    OnPropertyChanged("UseBackend");
                }
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        private void OnPropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;

            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        //TODO: Save and Load Settings into IsolatedStorage
        //private void LoadSettings()
        //{
            //using (var store = IsolatedStorageFile.GetUserStoreForApplication())
            //{
            //    using (var stream = new IsolatedStorageFileStream("settings.xml", System.IO.FileMode.OpenOrCreate, FileAccess.Read, store))
            //    {

            //    }
            //}
        //}
    }
}
